//
//  WDCustomButton.m
//  WeiDianGuanJia
//
//  Created by xieyingze on 2017/4/6.
//  Copyright © 2017年 谢英泽. All rights reserved.
//

#import "CustomButton.h"
#import "AppHeader.h"

@interface CustomButton ()

@property (nonatomic, assign) CGFloat width;
@property (nonatomic, assign) CGFloat height;

@end

@implementation CustomButton

- (instancetype)initWithCustomBttonType:(kCustomBttonType)buttonType size:(CGSize)size {
    self = [super init];
    if (self) {
        _type = buttonType;
        _width = size.width;
        _height = size.height;
    }
    return self;
}

- (CGRect)imageRectForContentRect:(CGRect)contentRect {
    if (_type == kCustomBttonTypeSmalll) {
        CGFloat width = 25.f;
        [self.titleLabel setTextAlignment:NSTextAlignmentCenter];
        return CGRectMake((_width - width)/2.f, 6.f, width, width);
    }else if (_type == kCustomBttonTypeNormal){
        CGFloat width = 30.f;
        [self.titleLabel setTextAlignment:NSTextAlignmentCenter];
        return CGRectMake((_width - width)/2.f, 6.f, width, width);
    }else{
        CGFloat width = 40.f;
        [self.titleLabel setTextAlignment:NSTextAlignmentCenter];
        return CGRectMake((_width - width)/2.f, 6.f, width, width);
    }
}

- (CGRect)titleRectForContentRect:(CGRect)contentRect {
    if (_type == kCustomBttonTypeSmalll) {
        CGFloat height = 14.f;
        return CGRectMake(kUI_Zero, _height - height - 2, _width, height);
    }else if (_type == kCustomBttonTypeNormal){
        CGFloat height = 16.f;
        return CGRectMake(kUI_Zero, _height - height - 2, _width, height);
    }else{
        CGFloat height = 20.f;
        return CGRectMake(kUI_Zero, _height - height - 2, _width, height);
    }
}

@end
